<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${path}/static/common/bootstrap-3.3.7-dist/css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="${path}/static/common/layui/css/layui.css"/>
</head>
<body>
	<form id="form" class="layui-form layui-form-pane" action="">
	
<!-- **********	0. user id..隐藏 hidden()	************	 -->
	  <!-- id 不用，，数据库自动自增 -->
	
<!-- **********	1.名字	************	 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">用户名字</label>
	    <div class="layui-input-block">
	      <input type="text" name="username" autocomplete="off" placeholder="用户名字" class="layui-input">
	    </div>
	  </div>
	  
<!-- **********	2.密码	************	 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">密码</label>
	    <div class="layui-input-block">
	      <input type="text" name="password" lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
	    </div>
	  </div>
  
	  
<!-- **********	3.邮箱	************	 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">邮箱</label>
	    <div class="layui-input-block">
	      <input type="text" name="email" autocomplete="off" placeholder="邮箱" class="layui-input">
	    </div>
	  </div>
	  
<!-- **********	4.手机号	************	 -->
	   <div class="layui-form-item">
	    <label class="layui-form-label">手机号</label>
	    <div class="layui-input-block">
	      <input type="text" name="phone" autocomplete="off" placeholder="手机号" class="layui-input">
	    </div>
	  </div>
	  
 <!-- **********	5.问题	************	 -->
	  <div class="layui-form-item">
	   <label class="layui-form-label">问题</label>
	   <div class="layui-input-block">
	     <input type="text" name="question" autocomplete="off" placeholder="问题" class="layui-input">
	   </div>
	 </div>
 
<!-- **********	6.回答 	************	 -->
	   <div class="layui-form-item">
	    <label class="layui-form-label">回答</label>
	    <div class="layui-input-block">
	      <input type="text" name="answer" autocomplete="off" placeholder="回答" class="layui-input">
	    </div>
	  </div>
	  
<!-- **********	7.角色   0：管理员、1：普通用户 引用模块	************	 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">角色</label>
	    <div class="layui-input-block">
	      <input type="radio" name="role" value="0" title="管理员">
	      <input type="radio" name="role" value="1" title="普通用户" checked>
	    </div>
	  </div>
	  	  
   </form>
   
   <button class="layui-btn" onclick="submitForm()">添加</button>
   
   
 <!-- JS具体实现方法 -->
   <script src="${path}/static/common/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
   <script src="${path}/static/common/layer/layer.js" type="text/javascript" charset="utf-8"></script>
   <script src="${path}/static/common/mylayer.js" type="text/javascript" charset="utf-8"></script>
   <script src="${path}/static/common/layui/layui.js" type="text/javascript" charset="utf-8"></script>
   
   	<!--  2020-03.20富文本引入 英语包 汉语包 -->
   <script src="${path}/static/common/kindeditor/kindeditor.js" type="text/javascript" charset="utf-8"></script>
   <script src="${path}/static/common/kindeditor/lang/zh_CN.js" type="text/javascript" charset="utf-8"></script>
   
   <script type="text/javascript">
/* 0.引用layui模块 */
   	   layui.use(["form", "upload"], function() {
   			var form = layui.form;
   	   });
   
/* 2.添加    按钮        发送insert到product后台*/
	   function submitForm() {
			$.post(
				"${path}/user/insert.action",
				$("#form").serialize(),
				function(result) {
					console.log(result);
					if(result.success) {
						mylayer.successMsg(result.msg);
						//当你在iframe页面关闭自身时获得当前弹出框的index索引
						var index = parent.layer.getFrameIndex(window.name);
						// js一个方法，定时器，1000毫秒之后自动执行function里面的代码
						setTimeout(function() {
							 // 关闭弹出层
							 parent.layer.close(index); 
							 // 刷新父页面
							 window.parent.location.reload();
						}, 1000);
					} else {
						mylayer.errorMsg(result.msg);
					}
				},
				"json"
			);
			
		}


	   
	</script>
</body>
</html>